var $;
layui.config({
    base : "js/"
}).use(['form','layer','element','jquery'],function(){
    var form = layui.form(),
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage;
    $ = layui.jquery;

    var user = [];
    form.on("submit(login)",function(){
        localStorage.token = "kyinfo_token";
         user = '{"username":"'+ $('.username').val() + '","password":"' + $('.password').val() + '"}';
        $.ajax({
            url : "http://localhost/ci/login/login/check",
            type : "post",
            data : {'data':user,'token':localStorage.token},
            dataType : "json",
            success : function(data){
                console.log(data);
                localStorage.user = data['user'];
                console.log(localStorage.user);
                if(data['login']==1){
                  location.href="http://localhost/ci";
                }else{
                    top.layer.msg(data['success']);
                    location.href="http://localhost/ci/login/login/login"
                }

            },
            error : function (data) {
                console.log(data);
                 //top.layer.close(index);
                 top.layer.msg("请求失败.");
            }
        })
        return false;
    })


})



